﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ExpressionMapper.Tests
{
    [TestClass]
    public class FacadeTests
    {
        [TestMethod]
        public void CreateShallowReturnsNotNull()
        {
            var mapper = ExpressionMapper.Mapper.Create<string, int>();
            Assert.IsNotNull(mapper);
            Assert.AreEqual(1, mapper("1"));
        }

        [TestMethod]
        public void CreateShallowReturnsIdentityFunctionOnSameTypes()
        {
            var mapper = ExpressionMapper.Mapper.Create<int, int>();
            Assert.AreEqual(1, mapper(1));

            var test = "test";
            var mapper1 = ExpressionMapper.Mapper.Create<string, string>();
            Assert.AreSame(test, test);

        }

        class A
        {
            
        }

        class B : A
        {
        }

        [TestMethod]
        public void CreateShallowReturnsIdentityFunctionOnAssignableTypes()
        {
            var mapper = ExpressionMapper.Mapper.Create<B, A>();
            A a = new A();
            object result = mapper(new B());
            Assert.AreEqual(a.GetType(), result.GetType());
            Assert.IsFalse(ReferenceEquals(a, result));
        }

    }
}